<template>
  <div>
    <a-card :bordered="false" class="table-card">
      <a-row>
        <a-col :span="8"
          ><div class="table-page-search-wrapper">
            <a-descriptions title="考核信息" bordered size="middle">
              <a-descriptions-item label="考核标题" :span="3">
                {{ assessInfo.title }}
              </a-descriptions-item>
              <a-descriptions-item label="截止时间" :span="3">
                {{ assessInfo.endTime }}
              </a-descriptions-item>
              <a-descriptions-item label="考核类型" :span="3">
                <a-tag color="orange">日常考核</a-tag>
              </a-descriptions-item>
              <a-descriptions-item label="考核状态" :span="3">
                <a-tag color="#2db7f5">
                  {{ statusOptionsFormat(assessInfo.status) }}
                </a-tag>
              </a-descriptions-item>
              <a-descriptions-item label="文件资料" :span="3">
                <span v-for="(item, index) in fileList" :key="index">
                  <a target="_blank" :href="item.url">{{ item.name }}</a>
                </span>
              </a-descriptions-item>
            </a-descriptions>
          </div></a-col
        >
        <a-col
          :span="16"
          style="border-left: 1.5px solid #ecedee; height: calc(100vh - 17vh)"
        >
          <biz-assess-details-info-add-form
            v-if="showAddModal"
            ref="bizAssessDetailsInfoAddForm"
            :assessItemOptions="assessItemOptions"
            :assessId="assessInfo.id"
            @ok="getList"
            @close="showAddModal = false"
          />
          <!-- 编辑 -->
          <biz-assess-details-info-edit-form
            v-if="showEditModal"
            ref="bizAssessDetailsInfoEditForm"
            :assessItemOptions="assessItemOptions"
            :assessId="assessInfo.id"
            @ok="getList"
            @close="showEditModal = false"
          />
          <advance-table
            title="考核项目详情列表"
            :pagination="{
              current: queryParam.pageNum,
              pageSize: queryParam.pageSize,
              total: total,
              showSizeChanger: true,
              showLessItems: true,
              showQuickJumper: true,
              showTotal: (total, range) =>
                `第 ${range[0]}-${range[1]} 条，总计 ${total} 条`,
              onChange: changeSize,
              onShowSizeChange: onShowSizeChange,
            }"
            tableKey="base-bizAssessDetailsInfo-index-table"
            rowKey="id"
            size="middle"
            @refresh="getList"
            :columns="columns"
            :data-source="bizAssessDetailsInfoList"
            :loading="loading"
            :format-conditions="true"
            :row-selection="{
              selectedRowKeys: selectedRowKeys,
              onChange: onSelectChange,
            }"
          >
            <div class="table-operations" slot="button">
              <a-button
                type="primary"
                @click="handleAdd"
                v-hasPermi="['biz:bizAssessDetailsInfo:add']"
                v-if="assessInfo.status == 0"
              >
                <a-icon type="plus" />新增
              </a-button>
              <a-button
                type="danger"
                v-if="!multiple && assessInfo.status == 0"
                :disabled="multiple"
                @click="handleDelete"
                v-hasPermi="['biz:bizAssessDetailsInfo:remove']"
              >
                <a-icon type="delete" />删除
              </a-button>
            </div>

            <span slot="assessItem" slot-scope="{ record }">
              {{ assessItemFormat(record) }}
            </span>

            <span slot="operation" slot-scope="{ text, record }">
              <span v-if="assessInfo.status == 0">
                <a @click="handleUpdate(record)"> 修改 </a>
                <a-divider type="vertical" />
                <a @click="handleDelete(record)"> 删除 </a>
              </span>
              <span v-if="assessInfo.status != 0">
                <a @click="handleGetDetails(record)"> 查看详情 </a>
              </span>
            </span>
            <span slot="rowindex" slot-scope="{ index }">
              {{ index + 1 }}
            </span>
          </advance-table></a-col
        >
      </a-row>

      <!-- 增加 -->
    </a-card>
  </div>
</template>
<script>
import {
  listBizAssessDetailsInfo,
  delBizAssessDetailsInfo,
  exportBizAssessDetailsInfo,
} from "@/api/biz/bizAssessDetailsInfo";
import { listBizAssessToDeptDetailsFile } from "@/api/biz/bizAssessToDeptDetailsFile";
import AdvanceTable from "@/components/pt/table/AdvanceTable";
import BizAssessDetailsInfoAddForm from "@/views/biz/assessdetailsinfo/modules/BizAssessDetailsInfoAddForm";
import BizAssessDetailsInfoEditForm from "@/views/biz/assessdetailsinfo/modules/BizAssessDetailsInfoEditForm";
export default {
  name: "BizAssessDetailsInfo",
  components: {
    AdvanceTable,
    BizAssessDetailsInfoAddForm,
    BizAssessDetailsInfoEditForm,
  },
  props: {
    assessInfo: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
      showAddModal: false,
      showEditModal: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 选中的主键集合
      selectedRowKeys: [],
      // 选中的数据集合
      selectedRows: [],
      // 高级搜索 展开/关闭
      advanced: false,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // label的百分比
      labelCol: { span: 6 },
      // 内容区域的百分比
      wrapperCol: { span: 18 },
      // 考核详情表格数据
      bizAssessDetailsInfoList: [],
      // 考核项目字典
      assessItemOptions: [],
      statusOptions: [],
      fileList: [],
      // 查询参数
      queryParam: {
        pageNum: 1,
        pageSize: 10,
        assessId: this.assessInfo.id,
      },
      columns: [
        {
          title: "序号",
          dataIndex: "rowindex",
          ellipsis: true,
          align: "center",
          width: "5%",
          scopedSlots: { customRender: "rowindex" },
        },
        {
          title: "考核项目",
          dataIndex: "assessItem",
          scopedSlots: { customRender: "assessItem" },
          align: "center",
          width: "10%",
        },
        {
          title: "考核指标",
          dataIndex: "assessTitle",
          ellipsis: true,
          align: "center",
          width: "20%",
        },
        {
          title: "考核标准",
          dataIndex: "assessContent",
          align: "center",
          ellipsis: true,
        },
        {
          title: "评分标准",
          dataIndex: "assessMark",
          align: "center",
          width: "20%",
          ellipsis: true,
        },
        {
          title: "最高分",
          dataIndex: "assessScore",
          align: "right",
          width: "8%",
        },
        {
          title: "操作",
          dataIndex: "operation",
          align: "center",
          width: "12%",
          scopedSlots: { customRender: "operation" },
        },
      ],
    };
  },
  created() {
    this.getList(this.assessInfo.id);
    this.getDicts("assess_item").then((response) => {
      this.assessItemOptions = response.data;
    });
    this.getDicts("assess_info_status").then((response) => {
      this.statusOptions = response.data;
    });
    this.handlelistBizAssessToDeptDetailsFile();
  },
  methods: {
    handlelistBizAssessToDeptDetailsFile() {
      listBizAssessToDeptDetailsFile({
        assessDeptDetailsId: this.assessInfo.id,
      }).then((response) => {
        this.fileList = response.data.list.map((item) => {
          return {
            name: item.fileName,
            url: item.fileUrl,
            uid: item.id,
            status: "done",
          };
        });
      });
    },
    /** 查询考核详情列表 */
    getList(assessId) {
      this.loading = true;
      this.queryParam.assessId = assessId;
      listBizAssessDetailsInfo(this.queryParam).then((response) => {
        this.bizAssessDetailsInfoList = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    // 考核项目字典翻译
    assessItemFormat(row) {
      if (row.assessItem) {
        return this.selectDictLabel(this.assessItemOptions, row.assessItem);
      } else {
        return "";
      }
    },
    // 考核项目字典翻译
    statusOptionsFormat(status) {
      if (status) {
        return this.selectDictLabel(this.statusOptions, status);
      } else {
        return "";
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParam.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParam = {
        pageNum: 1,
        pageSize: 10,
      };
      this.handleQuery();
    },
    /** 翻页操作 */
    onShowSizeChange(current, pageSize) {
      this.queryParam.pageSize = pageSize;
      this.getList();
    },
    /** 翻页操作 */
    onSizeChange(current, size) {
      this.queryParam.pageNum = 1;
      this.queryParam.pageSize = size;
      this.getList();
    },
    /** 翻页操作 */
    changeSize(current, pageSize) {
      this.queryParam.pageNum = current;
      this.queryParam.pageSize = pageSize;
      this.getList();
    },
    /** 翻页操作 */
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys;
      this.selectedRows = selectedRows;
      this.ids = this.selectedRows.map((item) => item.id);
      this.single = selectedRowKeys.length !== 1;
      this.multiple = !selectedRowKeys.length;
    },
    /** 查询折叠和展开操作 */
    toggleAdvanced() {
      this.advanced = !this.advanced;
    },
    handleAdd() {
      this.showAddModal = true;
      this.$nextTick(() => this.$refs.bizAssessDetailsInfoAddForm.handleAdd());
    },
    handleUpdate(record, ids) {
      this.showEditModal = true;
      this.$nextTick(() =>
        this.$refs.bizAssessDetailsInfoEditForm.handleUpdate(record, ids)
      );
    },
    handleGetDetails(record) {
      this.showEditModal = true;
      this.$nextTick(() =>
        this.$refs.bizAssessDetailsInfoEditForm.handleGetDetails(record)
      );
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      var that = this;
      const bizAssessDetailsInfoIds = row.id || this.ids;
      this.$confirm({
        title: "确认删除所选中数据?",
        onOk() {
          return delBizAssessDetailsInfo(bizAssessDetailsInfoIds).then(() => {
            that.onSelectChange([], []);
            that.getList(this.assessId);
            that.$message.success("删除成功", 3);
          });
        },
        onCancel() {},
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      var that = this;
      this.$confirm({
        title: "是否确认导出?",
        content: "此操作将导出当前条件下所有数据而非选中数据",
        onOk() {
          return exportBizAssessDetailsInfo(that.queryParam).then(
            (response) => {
              that.download(response.msg);
              that.$message.success("导出成功", 3);
            }
          );
        },
        onCancel() {},
      });
    },
  },
};
</script>
<style scoped>
/deep/.table-card {
  min-height: calc(100vh - 128px);
}
</style>
